package com.vision.sales.cm.db.data;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sf.gilead.pojo.gwt.LightEntity;

/**
 * 
 * @author Mark
 *
 */
@Entity
@Table(name = SalesmanProduct.TABLE)
public class SalesmanProduct extends LightEntity implements Serializable {

	private static final long serialVersionUID = -6981571480153878393L;
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	public static final String TABLE = "salesman_product";
	public static final String COL_SALESMAN_ID = "salesman_id";
	public static final String COL_PRODUCT_ID = "product_id";
	public static final String COL_COMMISSION_RATE = "commission_rate";
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	@Id
	@ManyToOne
	@JoinColumn(name = COL_SALESMAN_ID, nullable = false)
	private Salesman salesman;
	
	@Id
	@ManyToOne
	@JoinColumn(name = COL_PRODUCT_ID, nullable = false)
	private Product product;
	
	@Column(name = COL_COMMISSION_RATE, nullable = false)	
	private double commissionRate;
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	public SalesmanProduct() {
		
	}
	
	@Override
	public boolean equals(Object object) {
		if (object instanceof SalesmanProduct) {
			SalesmanProduct o = (SalesmanProduct) object;
			return salesman.equals(o.salesman)
					&& product.equals(o.product);
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		// TODO Implement
		return super.hashCode();
	}
	
	@Override
	public String toString() {
		return getSalesman().getId() + "-" + getProduct().getId();
	}
	
	public String getKey() {
		return getSalesman().getId() + "-" + getProduct().getId();
	}
	
	public String getNameLabel() {
		return getSalesman().getCode() + "-" + getProduct().getCode();
	}
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	public Salesman getSalesman() {
		return salesman;
	}

	public void setSalesman(Salesman salesman) {
		this.salesman = salesman;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public double getCommissionRate() {
		return commissionRate;
	}

	public void setCommissionRate(double commissionRate) {
		this.commissionRate = commissionRate;
	}
	
}
